import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../models/comic.dart';

// Mock data provider
final comicsProvider = StateNotifierProvider<ComicsNotifier, List<Comic>>((ref) {
  return ComicsNotifier();
});

final selectedGenreProvider = StateProvider<String>((ref) => 'For You');

final featuredComicsProvider = Provider<List<Comic>>((ref) {
  final comics = ref.watch(comicsProvider);
  return comics.where((comic) => comic.rating >= 4.5).toList();
});

final comicsByGenreProvider = Provider.family<List<Comic>, String>((ref, genre) {
  final comics = ref.watch(comicsProvider);
  if (genre == 'For You') {
    return comics;
  }
  return comics.where((comic) => comic.genres.contains(genre)).toList();
});

class ComicsNotifier extends StateNotifier<List<Comic>> {
  ComicsNotifier() : super([]) {
    _loadMockData();
  }

  void _loadMockData() {
    // Mock data based on ZenToon style
    state = [
      Comic(
        id: '1',
        title: 'Secret Romance',
        author: 'Artist One',
        description: 'A forbidden love story between two characters from different worlds.',
        coverImageUrl: 'https://ext.same-assets.com/2411567312/2108123692.png',
        genres: ['Romance', 'Adult'],
        rating: 4.8,
        chaptersCount: 45,
        status: 'ongoing',
        lastUpdated: DateTime.now().subtract(const Duration(days: 1)),
        isPremium: false,
      ),
      Comic(
        id: '2',
        title: 'Warrior\'s Path',
        author: 'Artist Two',
        description: 'An epic adventure of a young warrior discovering his true power.',
        coverImageUrl: 'https://ext.same-assets.com/2411567312/3592246325.jpeg',
        genres: ['Action', 'Adventure'],
        rating: 4.6,
        chaptersCount: 78,
        status: 'ongoing',
        lastUpdated: DateTime.now().subtract(const Duration(days: 2)),
        isPremium: true,
      ),
      Comic(
        id: '3',
        title: 'Mystic Academy',
        author: 'Artist Three',
        description: 'Students with magical powers navigate school life and dangerous mysteries.',
        coverImageUrl: 'https://ext.same-assets.com/2411567312/3319491162.jpeg',
        genres: ['Fantasy', 'School'],
        rating: 4.7,
        chaptersCount: 32,
        status: 'ongoing',
        lastUpdated: DateTime.now().subtract(const Duration(days: 3)),
        isPremium: false,
      ),
      Comic(
        id: '4',
        title: 'Space Guardians',
        author: 'Artist Four',
        description: 'Humanity\'s last hope against alien invasion in the far future.',
        coverImageUrl: 'https://ext.same-assets.com/2411567312/2201258949.jpeg',
        genres: ['Sci-Fi', 'Action'],
        rating: 4.5,
        chaptersCount: 56,
        status: 'completed',
        lastUpdated: DateTime.now().subtract(const Duration(days: 7)),
        isPremium: false,
      ),
      Comic(
        id: '5',
        title: 'Royal Harem',
        author: 'Artist Five',
        description: 'A prince must choose between love and duty in the royal court.',
        coverImageUrl: 'https://ext.same-assets.com/2411567312/1578322905.jpeg',
        genres: ['Harem', 'Romance'],
        rating: 4.4,
        chaptersCount: 67,
        status: 'ongoing',
        lastUpdated: DateTime.now().subtract(const Duration(days: 4)),
        isPremium: true,
      ),
    ];
  }

  void addToFavorites(String comicId) {
    // Implementation for adding to favorites
  }

  void removeFromFavorites(String comicId) {
    // Implementation for removing from favorites
  }
}

// Bottom navigation provider
final bottomNavIndexProvider = StateProvider<int>((ref) => 0);
